﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using WS.EKA.Utility;

namespace WS.EKA.Web.UI.Pages
{
    public partial class ChangePassword : PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        private void UpdateUser(User u)
        {
            XmlSerializerHelper.Serialize<User>(u, "User.xml");
        }

        protected void ChangePwdBtn_Click(object sender, EventArgs e)
        {
            string oldPassword = this.txtOldPassword.Text;
            string newPassword = this.txtPassword.Text;
            string confirmnewPassword = this.txtConfirmPassword.Text;
            if (string.IsNullOrEmpty(oldPassword) || string.IsNullOrEmpty(newPassword)
                || string.IsNullOrEmpty(confirmnewPassword))
            {
                this.WebMessageBox(this, "密码不能为空！");
                return;
            }
            if (newPassword != confirmnewPassword)
            {
                this.WebMessageBox(this, "两次密码不一致！");
                return;
            }
            var user = GetLoginUser();
            if (user.Password != oldPassword)
            {
                this.WebMessageBox(this, "旧密码错误！");
                return;
            }
            user.Password = newPassword;
            UpdateUser(user);
            this.WebMessageBox(this, "密码修改成功！");
        }
    }
}